home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / fsserial.zip / SERIAL.PAS < prev    next >
Pascal/Delphi Source File  |  1991-01-27  |  25KB  |  791 lines

  1. Unit Serial;
  2.  
  3. {     SERIAL.PAS - 14 Jan 91
  4.                    15 Jan 91 (Last Modification)
  5.  
  6.       This unit is designed to allow the user to use a FOSSIL driver for
  7.       a serial unit that is event-driven aware.  To do this, the input
  8.       from the modem is given an event status number just like the mouse or
  9.       keyboard.  All input is then routed directly through the event driver
  10.       for all your dialogs to use.  The output to the modem is in the form
  11.       of a series of events that you can use or direct calls via an object.
  12.       Note that these calls are the basics and do not halt for buffer
  13.       overruns in either Tx or Rx.  Your application program will have to
  14.       monitor the serCarrier and serTxBuffer events to keep track if there
  15.       is a carrier or if there is room in the TX buffer for more to be
  16.       sent.
  17.  
  18.       Note that this unit was written to take advantage of many of the
  19.       FOSSIL drivers out on the market such as X00.SYS or BNU.COM.  If
  20.       the system does not detect a FOSSIL driver in memory, then it
  21.       resorts to standard interrupt driven serial I/O without the ability
  22.       to open up more than one port at a time. (Currently... This may
  23.       change in the future)
  24.  
  25.       ----------------
  26.       REVISION HISTORY
  27.       ----------------
  28.  
  29.       01-14-91  Designed and created the test version of the FOSSIL only
  30.                 version.  The internal serial routines have not yet been
  31.       written to be used with this Unit.  Created the Event evSerial.
  32.       Added a bunch of BASIC routines to the serial driver and made sure
  33.       that the FSerial.Idle routine was passing the correct stuff!
  34.  
  35.       01-15-91  Added Event checks for Carrier and Transmission Buffer
  36.                 overflow.
  37.  
  38.       01-22-91  Rearranged the LSList system as a TCollection to improve
  39.                 the disposal procedure.  Also created the serCarrierReq and
  40.       serTxBufferReq events so that the user can request a port status in
  41.       case for some reason he missed the toggle event.
  42.  
  43.       01-27-91  Created a command entry to return a string if the receive
  44.                 buffer has several characters in it insted of trying to send
  45.       each and every one via an event.  Also changed the SERIAL.PAS activated
  46.       events to seperate procedures so that you can call them directly if you
  47.       inherit the Object or use it seperatly.  There is also a procedure to
  48.       disable this system from creating Command events.  You can use it
  49.       either way now...
  50.  
  51. }
  52. {$F+,O+,R-,S-}
  53.  
  54. {$DEFINE FOSSILDRIVER} {This will check if a FOSSIL driver is in place and
  55.                         will install a standard serial port if the driver
  56.                         is not in memory. If this is undefined, then the
  57.                         FOSSIL routines are not compiled in and you use the
  58.                         standard Serial routines regardless}
  59.  
  60. { DEFINE SERIALDRIVER} {If this is undefined, then all the standard serial
  61.                         routines are left out. If the FOSSIL driver is not
  62.                         in memory then you are out of luck...}
  63.  
  64. Interface
  65.  
  66. Uses Dos, Drivers, Views, Objects;
  67.  
  68. {----------------------------------------------------------------------------}
  69.  
  70. CONST evSerial      = $8000;   {Define a Serial Event Message}
  71.  
  72.       stDupSerial   = 195;     {Duplicate Port Requested}
  73.       stOpenError   = 194;     {Error opening the port}
  74.       stInvalidPort = 193;     {Invalid port number}
  75.       stInvalidBaud = 192;     {Invalid selected baud rate}
  76.       stCharUnavail = 191;     {Tried to read a char, but none available}
  77.  
  78.       serBaud       = 7100;    {Set Baud Rate       (Port,Baud)}
  79.                                {Fmt:  InfoByte=Port, InfoLong=+Baud SHL 16}
  80.       serSend       = 7101;    {Send a char         (Port,Byte)}
  81.                                {Fmt:  InfoByte=Port, InfoWord=+Byte SHL 8}
  82.       serInit       = 7104;    {Initialize a port   (Port)}
  83.       serDeInit     = 7105;    {Remove a port       (Port)}
  84.       serRaiseDTR   = 7106;    {Raise the DTR       (Port)}
  85.       serLowerDTR   = 7107;    {Lower the DTR       (Port)}
  86.       serPurgeRx    = 7108;    {Purge the Recv buf  (Port)}
  87.       serPurgeTx    = 7109;    {Purge output buf    (Port)}
  88.       serFlow       = 7115;    {Set Flow Control    (Port,Flow)}
  89.                                {Fmt:  InfoByte=Port, InfoWord=+Flow SHL 8}
  90.       serCarrierReq = 7116;    {Request the Carrier Status (Port)}
  91.       serTxBufferReq= 7117;    {Request Tx Buffer Status (Port)}
  92.  
  93.       serEventGenOn = 7118;    {Turn on Serial Event Generation}
  94.       serEventGenOff= 7119;    {Turn off Serial Event Generation}
  95.  
  96.       serCarrier    = 7120;    {Carrier Status      (Port,Status)}
  97.       serTxBuffer   = 7121;    {TxBuffer Status     (Port,Status)}
  98.       serRecvChar   = 7122;    {Received a char     (Port,Byte)}
  99.       serRecvLine   = 7123;    {Received a line     (Port,Ptr -> String)}
  100.  
  101. {----------------------------------------------------------------------------}
  102.  
  103. TYPE  FossilList = RECORD
  104.                       strsiz  : WORD;
  105.                       majver  : BYTE;
  106.                       minver  : BYTE;
  107.                       ident   : POINTER;
  108.                       ibufr   : WORD;
  109.                       ifree   : WORD;
  110.                       obufr   : WORD;
  111.                       ofree   : WORD;
  112.                       swidth  : BYTE;
  113.                       sheight : BYTE;
  114.                       baud    : BYTE;
  115.                    END;
  116.  
  117. TYPE  PTypes = (SerNone,SerStd,SerFossil);
  118.       PSList = ^LSList;
  119.       LSList = OBJECT(TObject)
  120.                   SerialPort  : BYTE;
  121.                   PortType    : PTypes;
  122.                   BaudBits    : BYTE;
  123.                   FlowControl : BYTE;
  124.                   Carrier     : BOOLEAN;
  125.                   TxBuffer    : BOOLEAN;
  126.                   CONSTRUCTOR Init(Port : BYTE);
  127.                   CONSTRUCTOR Load(VAR S : TStream);
  128.                   PROCEDURE Store(VAR S : TStream);
  129.                   DESTRUCTOR Done; VIRTUAL;
  130.                END;
  131.  
  132.       RecvRec = RECORD
  133.                    Port : BYTE;
  134.                    St   : STRING
  135.                 END;
  136.  
  137. TYPE  PSerial = ^FSerial;
  138.       FSerial = OBJECT(TView)
  139.                    OpenPorts     : PCollection;
  140.                    LastPort      : BYTE;
  141.                    EventGenerate : BOOLEAN;
  142. {$IFDEF FOSSILDRIVER}
  143.                    FossilUsed    : BOOLEAN;
  144.                    FossilInfo    : FossilList;
  145. {$ENDIF}
  146.                    ErrorInfo     : INTEGER;
  147.                    CONSTRUCTOR Init;
  148.                    CONSTRUCTOR Load(VAR S : TStream);
  149.                    PROCEDURE Store(VAR S : TStream);
  150.  
  151.                    PROCEDURE InitPort(Port : BYTE);
  152.                    PROCEDURE RemovePort(Port : BYTE);
  153.                    PROCEDURE SetBaud(Port : BYTE; Baud : WORD);
  154.                    PROCEDURE PurgeOutputBuf(Port : BYTE);
  155.                    PROCEDURE PurgeInputBuf(Port : BYTE);
  156.                    PROCEDURE SendChar(Port : BYTE; Ch : BYTE);
  157.                    PROCEDURE SendLine(Port : BYTE; Ln : STRING);
  158.                    FUNCTION  RecvChar(Port : BYTE) : CHAR;
  159.                    PROCEDURE DTRState(Port : BYTE; UpDown : BOOLEAN);
  160.                    PROCEDURE FlowControl(Port : BYTE; Item : BYTE);
  161.                    PROCEDURE SerialRequest(ReqType : WORD; Port : BYTE);
  162.                    PROCEDURE GenerateEvents(Action : BOOLEAN);
  163.  
  164.                    PROCEDURE Reset;
  165.                    DESTRUCTOR Done; VIRTUAL;
  166.                    PROCEDURE Idle; VIRTUAL;
  167.                    PROCEDURE HandleEvent(VAR Event : TEvent); VIRTUAL;
  168.                 END;
  169.  
  170. CONST RSerial: TStreamRec = (
  171.          ObjType: 7100;
  172.          VmtLink: Ofs(TypeOf(FSerial)^);
  173.          Load:    @FSerial.Load;
  174.          Store:   @FSerial.Store
  175.       );
  176.  
  177.       RSList: TStreamRec = (
  178.          ObjType: 7101;
  179.          VmtLink: Ofs(TypeOf(LSList)^);
  180.          Load:    @LSList.Load;
  181.          Store:   @LSList.Store
  182.       );
  183.  
  184. PROCEDURE RegisterSerial;
  185.  
  186. VAR   SerialSys : PSerial;
  187.  
  188. Implementation
  189.